<?php
/**
 * ==============================================
 * Copy right 2015-2016 http://wei.meididi88.com
 * ----------------------------------------------
 * This is not a free software, without any authorization is not allowed to use and spread.
 * ==============================================
 * @author: hy
 * @date: 2015-9-10
 * @version: v1.0.0
 */
namespace Home\Behaviors;

use Think\Behavior;

/**
 * 美容师收支行为扩展
 */
class BeauticianIncomeBehavior extends Behavior{
	
	public function run(&$params) {
// 		$dec = 0;
// 		if ($orderInfo ['coupon_id']) {
// 			$UserCouponModel = D('UserCoupon');
// 			$userCouponInfo = $UserCouponModel->where(array('id' => $params ['coupon_id']))->find();
// 			$this->assign('coupon', $userCouponInfo);
// 			$dec = $userCouponInfo ['c_type'] != 2?$userCouponInfo ['money_reduce']:$userCouponInfo ['money_amount'];
// 		}
		
// 		$pay = $orderInfo ['price'] - $dec;

		$pay = $params ['price'];
		$beautician_id = $params ['beautician_id'];
		
		$setting = getGlobleConfig();

		$inCome = round($pay * $setting['beautician_commission'], 2);
		$incomeInfo = array(
			'beautician_id' => $beautician_id,
			'type' => 'service',
			'income' => $inCome,
			'remark' => $params ['service_name'],
			'created' => time()
		);
		
		$inComeModel = D('IncomeStatement');
		$inComeModel->add($incomeInfo);
		
		$Beautician = D('Beautician');
		$beuaticianInfo = $Beautician->getBeauticianInfo($beautician_id);
		
		$serviceAmount = $inCome + $beuaticianInfo ['serviceAmount'];
		$Beautician->where(array('id' => $beautician_id))->save(compact('serviceAmount'));
		$Beautician->clearCache($beautician_id);
	}
}

?>